document
		.addEventListener('DOMContentLoaded',
				function() {
					document.getElementById('loginbutton').addEventListener(
							'click', login);
					document.getElementById('loginoutbutton').addEventListener(
							'click', loginout);
					document.getElementById('addbutton').addEventListener(
							'click', add);
					document.getElementById('settingbutton').addEventListener(
							'click', setting);
					document.getElementById('searchbutton').addEventListener(
							'click', function() {
								videolist(1)
							});
					document.getElementById('searchgobutton').addEventListener(
							'click', function() {
								videolist(0)
							});
					document.getElementById('batchbutton').addEventListener(
							'click', function() {
								batchadd()
							});
					document.getElementById('checkallbutton').addEventListener(
							'click', function() {
								checkall()
							});
					document.getElementById('uncheckallbutton')
							.addEventListener('click', function() {
								uncheckall()
							});
					document.getElementById('filterKey').addEventListener(
							'keyup', function() {
								filterBykey()
							});
					document.getElementById('createcodebutton')
							.addEventListener('click', function() {
								createCode()
							});
					document.getElementById('checkCode').addEventListener(
							'click', function() {
								createCode()
							});
					document.getElementById('winCloseButton').addEventListener(
							'click', function() {
								window.close();
							});

					document.getElementById('tabsName-1').addEventListener(
							'click', function() {
								selectTabs("#tabs-1")
							});
					document.getElementById('tabsName-2').addEventListener(
							'click', function() {
								MysetItem("Arraytitle", null);
								MysetItem("Arrayurl", null);
								selectTabs("#tabs-2");
							});
					document.getElementById('tabsName-3').addEventListener(
							'click', function() {
								selectTabs("#tabs-3")
							});
					document.getElementById('tabsName-4').addEventListener(
							'click', function() {
								selectTabs("#tabs-4")
							});

				});
document.onkeydown=function(event){ 
    e = event ? event :(window.event ? window.event : null); 
    if(e.keyCode==13){ 
        //执行的方法  
        //alert('回车检测到了'); 
    	if(document.getElementById('login_div').style.display != "none"){
    		document.getElementById('loginbutton').click();
    	}
    } 
} 

var xmlhttp;
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
	xmlhttp = new XMLHttpRequest();
} else {// code for IE6, IE5
	xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}

/*
 * 登录
 */
function login() {
	validateResult = validate();
	if (validateResult == '1') {
		alert("请输入验证码！");
		return false;
	} else if (validateResult == '2') {
		alert("验证码输入错误！");
		return false;
	} else if (validateResult == '3') {

	}
	var str = "";
	var elem = document.forms['loginForm'].elements;
	for ( var i = 0; i < elem.length; i++) {
		if (i != 0)
			str += "&";
		str += elem[i].name + "=" + elem[i].value;
	}
	xmlhttp.onreadystatechange = loginCallback;
	xmlhttp.open("POST", "http://api.cntv.cn/client/auth", false);
	xmlhttp.setRequestHeader("Content-Type",
			"application/x-www-form-urlencoded");
	xmlhttp.send(str);
}
/*
 * 登录回调
 */
function loginCallback() {
	if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
		var json = JSON.parse(xmlhttp.responseText);
		if (json.ret == "succ") {
			initPage();
		} else {
			alert(json.msg);
		}

	}
}

/*
 * 退出
 */
function loginout() {
	var str = "";
	xmlhttp.onreadystatechange = loginoutCallback;
	xmlhttp.open("GET", "http://api.cntv.cn/client/logout", false);
	xmlhttp.setRequestHeader("Content-Type",
			"application/x-www-form-urlencoded");
	xmlhttp.send(str);
}
/*
 * 退出回调
 */
function loginoutCallback() {
	if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
		initPage();
	}
}

/*
 * 单片添加
 */
function add() {
	var str = "";
	var elem = document.forms['addForm'].elements;
	for ( var i = 0; i < elem.length; i++) {
		if (i != 0)
			str += "&";
		str += elem[i].name + "=" + elem[i].value;
	}
	xmlhttp.onreadystatechange = addCallback;
	xmlhttp.open("POST", "http://api.cntv.cn/client/add", false);
	xmlhttp.setRequestHeader("Content-Type",
			"application/x-www-form-urlencoded");
	xmlhttp.send(str);
}
/*
 * 单片添加回调
 */
function addCallback() {
	if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
		var json = JSON.parse(xmlhttp.responseText);
		alert(json.msg);
		location.reload();
	}
}

/*
 * 批量添加
 */
function batchadd() {
	var str = "";
	/* 获取选中的项 */
	var i = 0;
	$('.checkitem:checked').each(function() {
		if (i != 0) {
			str += "&";
		}
		url = document.getElementById("url_" + i).value;
		// title = document.getElementById("title_"+i).value;
		// alert(title);
		str += "&url[]=" + url + '';
		// str += "&title[]=" + title + '';
		i++;
	});
	cat_id = encodeURIComponent(document.getElementById("cat_id").value);
	str += "&cat_id=" + cat_id;
	repeat_id = document.getElementById("repeat_id").value;
	str += "&repeat_id=" + repeat_id;
	partner_id = document.getElementById("partner_id").value;
	str += "&partner_id=" + partner_id;
	album_id = document.getElementById("album_id").value;
	str += "&album_id=" + album_id;
	special_id = document.getElementById("special_id").value;
	str += "&special_id=" + special_id;
	if (document.getElementById("sendtype").checked) {
		sendtype = '1';
	}
	str += "&sendtype=" + sendtype;

	xmlhttp.onreadystatechange = batchaddCallback;
	xmlhttp.open("POST", "http://api.cntv.cn/client/batchadd", false);
	xmlhttp.setRequestHeader("Content-Type",
			"application/x-www-form-urlencoded");
	xmlhttp.send(str);
}
/*
 * 全选
 */
function checkall() {
	// alert("checkall");
	var code_Values = document.getElementsByClassName("checkitem");
	for (i = 0; i < code_Values.length; i++) {
		if (code_Values[i].type == "checkbox") {
			code_Values[i].checked = true;
		}
	}
}
/*
 * 取消全选
 */
function uncheckall() {
	var code_Values = document.getElementsByClassName("checkitem");
	for (i = 0; i < code_Values.length; i++) {
		if (code_Values[i].type == "checkbox") {
			code_Values[i].checked = false;
		}
	}
}
/*
 * 批量添加回调
 */
function batchaddCallback() {
	if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
		var json = JSON.parse(xmlhttp.responseText);
		alert(json.msg);
		//document.getElementById('tabsName-2').click();
		MysetItem("Arraytitle", null);
		MysetItem("Arrayurl", null);
		//location.reload();
		selectTabs("#tabs-2");
	}
}

/*
 * 取得马甲信息
 */
function getrepeat() {
	var str = "";
	xmlhttp.onreadystatechange = getrepeatCallback;
	xmlhttp.open("GET", "http://api.cntv.cn/client/getrepeat", false);
	xmlhttp.setRequestHeader("Content-Type",
			"application/x-www-form-urlencoded");
	xmlhttp.send(str);
}
/*
 * 取得马甲信息回调
 */
function getrepeatCallback() {
	if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
		// alert(xmlhttp.responseText);
		// initPage();
		var json = JSON.parse(xmlhttp.responseText);
		repeat_id_select = document.getElementById("repeat_id");
		repeat_id_select.options.length = 0;
		set_repeat_id_select = document.getElementById("set_repeat_id");
		set_repeat_id_select.options.length = 0;
		if (repeat_id_select != null) {
			repeat_id_select.options.add(new Option("选择马甲", "0"));
		}
		if (set_repeat_id_select != null) {
			set_repeat_id_select.options.add(new Option("选择马甲", "0"));
		}
		if (json.ret == 'succ') {
			// @TODO
			$.each(json.data, function(index, d) {
				if (repeat_id_select != null) {
					repeat_id_select.options.add(new Option(d.repeat_name,
							d.repeat_id));
				}
				if (set_repeat_id_select != null) {
					set_repeat_id_select.options.add(new Option(d.repeat_name,
							d.repeat_id));
				}
			});
		} else {
			if (repeat_id_select != null) {
				repeat_id_select.options.add(new Option("马甲1", "1"));
				repeat_id_select.options.add(new Option("马甲2", "2"));
			}
			if (set_repeat_id_select != null) {
				set_repeat_id_select.options.add(new Option("马甲1", "1"));
				set_repeat_id_select.options.add(new Option("马甲2", "2"));
			}
		}
	}
}

/*
 * 取得合作伙伴信息
 */
function getpartner() {
	var str = "";
	xmlhttp.onreadystatechange = getpartnerCallback;
	xmlhttp.open("GET", "http://api.cntv.cn/client/getpartner", false);
	xmlhttp.setRequestHeader("Content-Type",
			"application/x-www-form-urlencoded");
	xmlhttp.send(str);
}
/*
 * 取得合作伙伴信息回调
 */
function getpartnerCallback() {
	if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
		var json = JSON.parse(xmlhttp.responseText);
		partner_id_select = document.getElementById("partner_id");
		partner_id_select.options.length = 0;
		set_partner_id_select = document.getElementById("set_partner_id");
		set_partner_id_select.options.length = 0;
		if (partner_id_select != null) {
			partner_id_select.options.add(new Option("合作伙伴", "0"));
		}
		if (set_partner_id_select != null) {
			set_partner_id_select.options.add(new Option("合作伙伴", "0"));
		}
		if (json.ret == 'succ') {
			// @TODO
			$.each(json.data, function(index, d) {
				if (partner_id_select != null) {
					partner_id_select.options.add(new Option(d.title,
							d.partner_id));
				}
				if (set_partner_id_select != null) {
					set_partner_id_select.options.add(new Option(d.title,
							d.partner_id));
				}
			});
		} else {
			if (partner_id_select != null) {
				partner_id_select.options.add(new Option("合作伙伴1", "1"));
				partner_id_select.options.add(new Option("合作伙伴2", "2"));
			}
			if (set_partner_id_select != null) {
				set_partner_id_select.options.add(new Option("合作伙伴1", "1"));
				set_partner_id_select.options.add(new Option("合作伙伴2", "2"));
			}
		}
	}
}

/*
 * 取得视频列表
 */
function videolist(pagenum) {
	if (pagenum == 0) {
		pagenum = document.getElementById("pagenum").value;
	}
	var str = "?format=json&page=" + pagenum + "&pagesize=5";
	select = document.getElementById("type");
	type = select.options[select.selectedIndex].value;
	keyword = encodeURIComponent(document.getElementById("keyword").value);
	// alert(keyword);
	if (type == "title") {
		str += "&title=" + keyword;
	} else if (type == "url") {
		str += "&url=" + keyword;
	}

	xmlhttp.onreadystatechange = videolistCallback;
	xmlhttp.open("GET", "http://api.cntv.cn/client/videolist" + str, false);
	xmlhttp.setRequestHeader("Content-Type",
			"application/x-www-form-urlencoded");
	xmlhttp.send();
}
/*
 * 取得视频列表回调
 */
function videolistCallback() {
	if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
		// alert(xmlhttp.responseText);
		var data = JSON.parse(xmlhttp.responseText);
		var tab = document.getElementById("videolist");
		// alert(tab.rows.length);
		// for(var i=1;i<=tab.rows.length;i++) {
		// for(var j=1;j<tab.rows[i].cells.length;j++) {
		// var tr = tab.rows[i]; alert(i);
		// tr.parentNode.removeChild(tr);
		// }
		// }
		var table = "<table class=\"tbl lstb\">";
		table += "<tr>";
		table += "<th>状态</th>";
		table += "<th>标题</th>";
		table += "<th>时间</th>";
		table += "<th>备注</th>";
		table += "</tr>";
		$.each(data.data, function(index, d) {
			// 视频采集状态 10：待采集 15：采集中 20：已采集30：采集失败 35：送审中 40：已送审50：送审失败
			if (d.status == '10') {
				var statusName = "待采集";
			} else if (d.status == '15') {
				var statusName = "采集中";
			} else if (d.status == '20') {
				var statusName = "已采集";
			} else if (d.status == '30') {
				var statusName = "采集失败";
			} else if (d.status == '35') {
				var statusName = "送审中";
			} else if (d.status == '40') {
				var statusName = "已送审";
			} else if (d.status == '50') {
				var statusName = "送审失败";
			} else {
				var statusName = "未知";
			}

			table += "<tr>";
			table += "<td>" + statusName + "</td>";
			table += "<td>" + d.title + "</td>";
			table += "<td>" + d.add_time + "</td>";
			table += "<td>" + d.url + "</td>";
			table += "</tr>";

			// alert(d.title);
			/*
			 * var row = tab.insertRow(-1); row.id = "row" + index; var cell1 =
			 * row.insertCell(-1); var cell2 = row.insertCell(-1); var cell3 =
			 * row.insertCell(-1); var cell4 = row.insertCell(-1); // <tr><th>状态</th><th>标题</th><th>时间</th><th>备注</th></tr>
			 * cell1.innerHTML = "<td><input type=\"checkbox\" value=\"" +
			 * d.id + "\" name=\"id\" /></td>"; cell2.innerHTML = "<td>" +
			 * d.title + "</td>"; cell3.innerHTML = "<td>" + d.add_time + "</td>";
			 * cell4.innerHTML = "<td>" + d.url + "</td>";
			 */
		})
		table += "</table>";
		tab.innerHTML = table;

		listinfo = "<span id=\"listtotal\">共" + data.total + "条信息</span>";

		if (data.currentpage > 1) {
			prePage = data.currentpage - 1;
		} else {
			prePage = 1;
		}
		if (data.currentpage >= data.totalpages) {
			nextPage = data.totalpages;
		} else {
			nextPage = data.currentpage + 1;
		}
		listinfo += "<a href=\"?page=" + prePage
				+ "#tabs-4\" id=\"firstButton\">|<<</a>";
		if (data.totalpages > 5) {
			/*
			 * if ((data.currentpage + 5) > data.totalpages) { perBlock =
			 * data.totalpages } else { perBlock = data.currentpage + 5; }
			 */
			hasMore = true;

			currentBlock = Math.floor(data.currentpage / 6) * 5 + 1;
			if ((currentBlock + 5) > data.totalpages) {
				perBlock = data.totalpages + 1;
			} else {
				perBlock = currentBlock + 5;
			}

			for ( var num = currentBlock; num < perBlock; num++) {
				if (data.currentpage == num) {
					listinfo += "<a href=\"?page="
							+ num
							+ "#tabs-4\" class=\"cur\" class=\"pageButton_class\" id=\"pageButton_"
							+ num + "\">" + num + "</a>";
				} else {
					listinfo += "<a href=\"?page="
							+ num
							+ "#tabs-4\" class=\"pageButton_class\"  id=\"pageButton_"
							+ num + "\">" + num + "</a>";
				}
			}
		} else {
			perBlock = data.totalpages;
			hasMore = false;
			for ( var num = 1; num <= perBlock; num++) {
				if (data.currentpage == num) {
					listinfo += "<a href=\"?page="
							+ num
							+ "#tabs-4\" class=\"cur\" class=\"pageButton_class\" id=\"pageButton_"
							+ num + "\">" + num + "</a>";
				} else {
					listinfo += "<a href=\"?page="
							+ num
							+ "#tabs-4\" class=\"pageButton_class\"  id=\"pageButton_"
							+ num + "\">" + num + "</a>";
				}
			}
		}
		if (data.currentpage >= data.totalpages) {
			listinfo += "<a href=\"?page=" + nextPage
					+ "#tabs-4\" id=\"lastButton\">>>|</a>";
		} else {
			listinfo += " ...<a href=\"?page=" + nextPage
					+ "#tabs-4\" id=\"lastButton\">>>|</a>";
		}
		/*
		 * if (perBlock > 1) { listinfo += "<a href=\"#\" id=\"firstButton\">|<<</a>"; }
		 * 
		 * for ( var num = data.currentpage; num <= perBlock; num++) { if
		 * (data.currentpage == num) { listinfo += "<a href=\"#\" class=\"cur\"
		 * id=\"pageButton_" + num + "\">" + num + "</a>"; } else { listinfo += "<a
		 * href=\"#\" id=\"pageButton_" + num + "\">" + num + "</a>"; } }
		 * 
		 * if (perBlock > 1) { if (hasMore) { listinfo += " ...<a href=\"#\"
		 * id=\"lastButton\">>>|</a>"; } else { listinfo += "<a href=\"#\"
		 * id=\"lastButton\">>>|</a>"; } }
		 */

		var pageInfo = document.getElementById("listinfo");
		pageInfo.innerHTML = listinfo;

		document.getElementById('firstButton').addEventListener('click',
				function() {
					videolist(prePage)
				});
		document.getElementById('lastButton').addEventListener('click',
				function() {
					videolist(nextPage)
				});

		/*
		 * if (data.totalpages > 5) { for ( var num = data.currentpage; num <=
		 * perBlock; num++) { if (data.currentpage == num) { } else {
		 * document.getElementById("pageButton_" + num)
		 * .addEventListener('click', function() { videolist(""+i+"p") });
		 * 
		 * //document.getElementById("pageButton_" +
		 * num).setAttribute("title","num"+num); } } } else { for ( var num = 1;
		 * num <= perBlock; num++) { if (data.currentpage == num) { } else {
		 * 
		 * document.getElementById("pageButton_" + num)
		 * .addEventListener('click', function() { videolist(num) });
		 * 
		 * //document.getElementById("pageButton_" +
		 * num).setAttribute("href","num"+num);
		 * //alert(document.getElementById("pageButton_" + num)); } } }
		 */
		// <span id="listtotal">共25条信息</span><a href="">|<<</a><a
		// href="">1</a><a href="" class="cur">2</a><a
		// href="">3</a><a href="">4</a><a href="">5</a> ...<a href="">>>|</a>
		// initPage();
	}
}
/*
 * 取得queryString参数
 */
function GetRequest() {
	var url = location.search; // 获取url中"?"符后的字串
	var theRequest = new Object();
	if (url.indexOf("?") != -1) {
		var str = url.substr(1);
		strs = str.split("&");
		for ( var i = 0; i < strs.length; i++) {
			theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
		}
	}
	return theRequest;
}
/*
 * 修改表格
 */
function delTableTr(id) {
	var tab = document.getElemntsByTagId("id");
	for ( var i = 0; i < tab.rows.length; i++) {
		for ( var j = 1; j < tab.rows[i].cells.length; j++) {
			// var obj=tab.rows[i][j].getElementsByTagName("input")[0];
			// if(obj!=null && obj.type="checkbox" && obj.checked=true) {//
			// 你没说需求我就直接将第一行中有checkbox且为true的删除
			// var tr=obj.parentNode.parentNode;
			// tr.parentNode.removeChild(tr);
			// }
			tr.parentNode.removeChild(tr);
		}
	}
}

/*
 * 单片提交页面
 */
function addTab() {
	// 转载本地存储到页面表单
	$("#title").val(MygetItem("title"));
	$("#tag").val(MygetItem("tag"));
	$("#intro").val(MygetItem("intro"));


	cat_id_select = document.getElementById("cat_id");
	set_cat_id = MygetItem("set_cat_id");
	for ( var i = 0; i < cat_id_select.options.length; i++) {
		if (cat_id_select.options[i].value == set_cat_id) {
			cat_id_select.options[i].selected = true;
		}
	}
	// $("#cat_id").val(MygetItem("repeat_id"));
	getrepeat();
	repeat_id_select = document.getElementById("repeat_id");
	for ( var i = 0; i < repeat_id_select.options.length; i++) {
		if (repeat_id_select.options[i].value == MygetItem("set_repeat_id")) {
			repeat_id_select.options[i].selected = true;
		}
	}
	// $("#repeat_id").val(MygetItem("set_repeat_id"));
	getpartner();
	partner_id_select = document.getElementById("partner_id");
	for ( var i = 0; i < partner_id_select.options.length; i++) {
		if (partner_id_select.options[i].value == MygetItem("set_partner_id")) {
			partner_id_select.options[i].selected = true;
		}
	}
	// $("#partner_id").val(MygetItem("set_partner_id"));
	cover_checkbox = document.getElementsByClassName("cover");

	var coverAry = JSON.parse(MygetItem("set_cover"));
	if (coverAry != null) {
		for ( var i = 0; i < cover_checkbox.length; i++) {
			for ( var j = 0; j < coverAry.length; j++) {
				if (cover_checkbox[i].value == coverAry[j]) {
					cover_checkbox[i].checked = true;
				}
			}

		}
	}
	// $("#cover").val(MygetItem("set_cover"));
	$("#album_id").val(MygetItem("set_album_id"));
	$("#special_id").val(MygetItem("set_special_id"));

	$("#url").val(MygetItem("url"));
	$("#sendtype").val(MygetItem("sendtype"));
	$("#format").val(MygetItem("format"));
}

/*
 * 发布设置页面
 */
function settingTab() {
	// 转载本地存储到页面表单
	cat_id_select = document.getElementById("set_cat_id");
	for ( var i = 0; i < cat_id_select.options.length; i++) {
		if (cat_id_select.options[i].value == MygetItem("set_cat_id")) {
			cat_id_select.options[i].selected = true;
		}
	}
	// $("#cat_id").val(MygetItem("repeat_id"));
	getrepeat();
	repeat_id_select = document.getElementById("set_repeat_id");
	for ( var i = 0; i < repeat_id_select.options.length; i++) {
		if (repeat_id_select.options[i].value == MygetItem("set_repeat_id")) {
			repeat_id_select.options[i].selected = true;
		}
	}
	// $("#repeat_id").val(MygetItem("set_repeat_id"));
	getpartner();
	partner_id_select = document.getElementById("set_partner_id");
	for ( var i = 0; i < partner_id_select.options.length; i++) {
		if (partner_id_select.options[i].value == MygetItem("set_partner_id")) {
			partner_id_select.options[i].selected = true;
		}
	}
	// $("#partner_id").val(MygetItem("set_partner_id"));
	cover_checkbox = document.getElementsByClassName("set_cover");
	var coverAry = MygetItem("set_cover");
	if (coverAry != null) {
		var coverAryJson = JSON.parse(coverAry);
		for ( var i = 0; i < cover_checkbox.length; i++) {
			for ( var j = 0; j < coverAryJson.length; j++) {
				if (cover_checkbox[i].value == coverAryJson[j]) {
					cover_checkbox[i].checked = true;
				}
			}

		}
	}

	// $("#cover").val(MygetItem("set_cover"));
	$("#set_album_id").val(MygetItem("set_album_id"));
	$("#set_special_id").val(MygetItem("set_special_id"));
}

/*
 * 发布设置
 */
function setting() {
	// 表单设置到本地存储
	// 发送给扩展模块
	cat_id_select = document.getElementById("set_cat_id");
	var cat_id = cat_id_select.options[cat_id_select.options.selectedIndex].value

	repeat_id_select = document.getElementById("set_repeat_id");
	var repeat_id = repeat_id_select.options[repeat_id_select.options.selectedIndex].value

	partner_id_select = document.getElementById("set_partner_id");
	var partner_id = partner_id_select.options[partner_id_select.options.selectedIndex].value

	var coverAry = new Array();
	cover_checkbox = document.getElementsByClassName("set_cover");
	for ( var i = 0; i < cover_checkbox.length; i++) {
		if (cover_checkbox[i].checked) {
			coverAry.push(cover_checkbox[i].value);
		}
	}
	var partner_id = partner_id_select.options[partner_id_select.options.selectedIndex].value

	MysetItem("set_cat_id", cat_id);
	MysetItem("set_repeat_id", repeat_id);
	MysetItem("set_partner_id", partner_id);
	MysetItem("set_cover", JSON.stringify(coverAry));
	MysetItem("set_album_id", $("#set_album_id").val());
	MysetItem("set_special_id", $("#set_special_id").val());
	alert("设置成功！");
}

/*
 * 批量添加页面
 */
function batchaddTab() {
	var tab = document.getElementById("batchlist");
	// 如果是ie
	if (document.all) {
		var table = "<table class=\"tbl lstb\" id=\"hmhm\">";
		table += "<tr>";
		table += "<th>选择</th>";
		table += "<th>标题</th>";
		table += "<th>url</th>";
		table += "</tr>";

		var Arraytitle = MygetItem("Arraytitle");
		var Aurl = MygetItem("Arrayurl");
		if (Aurl != null && Arraytitle != null && Aurl !="" && Arraytitle !="" ) {
			var ArraytitleJson = JSON.parse(Arraytitle);
			var AurlJson = JSON.parse(Aurl);
			for ( var i = 0; i < AurlJson.length; ++i) {
				table += "<tr>";
				table += "<td><input  class=\"checkitem\"  type=\"checkbox\" value=\""
						+ i + "\"/ id=\"id_" + i + "\"></td>";
				table += "<td><input   type=\"hidden\" value=\""
						+ ArraytitleJson[i] + "\"/ id=\"title_" + i + "\">"
						+ ArraytitleJson[i] + "</td>";
				table += "<td><input   type=\"hidden\" value=\"" + AurlJson[i]
						+ "\"/ id=\"url_" + i + "\">" + AurlJson[i] + "</td>";
				table += "</tr>";
				/*
				 * var tab = document.getElementById("hmhm"); var row =
				 * tab.insertRow(-1); row.id = "row" + i; var cell1 =
				 * row.insertCell(-1); var cell2 = row.insertCell(-1); var cell3 =
				 * row.insertCell(-1); cell1.innerHTML = "<td><input
				 * type=\"checkbox\" value=\"\"/></td>"; cell2.innerHTML = "<td>" +
				 * Arraytitle[i] + "</td>"; cell3.innerHTML = "<td>" +
				 * Aurl[i] + "</td>"; num++;
				 */

			}
			table += "</table>";
			var cat_id = MygetItem("set_cat_id");
			var repeat_id = MygetItem("set_repeat_id");
			var partner_id = MygetItem("set_partner_id");
			var album_id = MygetItem("set_album_id");
			var special_id = MygetItem("set_special_id");
			var setDiv = "<div style='display:none;'>";
			setDiv += "<input type=\"text\" id=\"cat_id\" name=\"cat_id\" value=\""
					+ cat_id + "\" />";
			setDiv += "<input type=\"text\" id=\"repeat_id\" name=\"repeat_id\" value=\""
					+ repeat_id + "\" />";
			setDiv += "<input type=\"text\" id=\"partner_id\" name=\"partner_id\" value=\""
					+ partner_id + "\" />";
			setDiv += "<input type=\"text\" id=\"album_id\" name=\"album_id\" value=\""
					+ album_id + "\" />";
			setDiv += "<input type=\"text\" id=\"special_id\" name=\"special_id\" value=\""
					+ special_id + "\" />";
			setDiv += "</div>";
			tab.innerHTML = table + setDiv;
			var hmnum = document.getElementById("hmnum");
			hmnum.innerText = "共" + AurlJson.length + "条信息"; // alert(Aurl.length);
		}else{
			table += "</table>";
			tab.innerHTML = table;
		}
		// 其他浏览器
	} else {
		var table = "<table class=\"tbl lstb\">";
		table += "<tr>";
		table += "<th>选择</th>";
		table += "<th>标题</th>";
		table += "<th>url</th>";
		table += "</tr>";

		var Arraytitle = MygetItem("Arraytitle");
		var Aurl = MygetItem("Arrayurl");
		
		if (Aurl != null && Arraytitle != null && Aurl !="" && Arraytitle !="") {
			var ArraytitleJson = JSON.parse(Arraytitle);
			var AurlJson = JSON.parse(Aurl);
			for ( var i = 0; i < AurlJson.length; ++i) {
				table += "<tr>";
				table += "<td><input  class=\"checkitem\"  type=\"checkbox\" value=\""
						+ i + "\"/ id=\"id_" + i + "\"></td>";
				table += "<td><input   type=\"hidden\" value=\""
						+ ArraytitleJson[i] + "\"/ id=\"title_" + i + "\">"
						+ ArraytitleJson[i] + "</td>";
				table += "<td><input   type=\"hidden\" value=\"" + AurlJson[i]
						+ "\"/ id=\"url_" + i + "\">" + AurlJson[i] + "</td>";
				table += "</tr>";
				/*
				 * var tab = document.getElementById("hmhm"); var row =
				 * tab.insertRow(-1); row.id = "row" + i; var cell1 =
				 * row.insertCell(-1); var cell2 = row.insertCell(-1); var cell3 =
				 * row.insertCell(-1); cell1.innerHTML = "<td><input
				 * type=\"checkbox\" value=\"\"/></td>"; cell2.innerHTML = "<td>" +
				 * Arraytitle[i] + "</td>"; cell3.innerHTML = "<td>" +
				 * Aurl[i] + "</td>";
				 */
			}
			table += "</table>";
			var cat_id = MygetItem("set_cat_id");
			var repeat_id = MygetItem("set_repeat_id");
			var partner_id = MygetItem("set_partner_id");
			var album_id = MygetItem("set_album_id");
			var special_id = MygetItem("set_special_id");
			var setDiv = "<div style='display:none;'>";
			setDiv += "<input type=\"text\" id=\"cat_id\" name=\"cat_id\" value=\""
					+ cat_id + "\" />";
			setDiv += "<input type=\"text\" id=\"repeat_id\" name=\"repeat_id\" value=\""
					+ repeat_id + "\" />";
			setDiv += "<input type=\"text\" id=\"partner_id\" name=\"partner_id\" value=\""
					+ partner_id + "\" />";
			setDiv += "<input type=\"text\" id=\"album_id\" name=\"album_id\" value=\""
					+ album_id + "\" />";
			setDiv += "<input type=\"text\" id=\"special_id\" name=\"special_id\" value=\""
					+ special_id + "\" />";
			setDiv += "</div>";
			tab.innerHTML = table + setDiv;
			var hmnum = document.getElementById("hmnum");
			hmnum.textContent = "共" + AurlJson.length + "条信息";// alert(Aurl.length)
		}else{
			table += "</table>";
			tab.innerHTML = table;
		}

	}
}
/*
 * 过滤url
 */
function filterBykey() {
	var tab = document.getElementById("batchlist");
	var filterKey = document.getElementById("filterKey").value;
	// 如果是ie
	if (document.all) {
		var table = "<table class=\"tbl lstb\" id=\"hmhm\">";
		table += "<tr>";
		table += "<th>选择</th>";
		table += "<th>标题</th>";
		table += "<th>url</th>";
		table += "</tr>";

		/*
		var Arraytitle = eval("(" + MygetItem("Arraytitle") + ")");
		var Aurl = eval("(" + MygetItem("Arrayurl") + ")");
		if (Aurl != null && Arraytitle != null) {
		*/
		var listIndex = 0;
		var Arraytitle = MygetItem("Arraytitle");
		var Aurl = MygetItem("Arrayurl");
		if (Aurl != null && Arraytitle != null && Aurl !="" && Arraytitle !="" ) {
			var ArraytitleJson = JSON.parse(Arraytitle);
			var AurlJson = JSON.parse(Aurl);
			for ( var i = 0; i < AurlJson.length; ++i) {
				if (AurlJson[i].indexOf(filterKey) >= 0) {
					table += "<tr>";
					table += "<td><input  class=\"checkitem\"  type=\"checkbox\" value=\""
							+ i + "\"/ id=\"id_" + listIndex + "\"></td>";
					table += "<td><input   type=\"hidden\" value=\""
							+ ArraytitleJson[i] + "\"/ id=\"title_" + listIndex
							+ "\">" + ArraytitleJson[i] + "</td>";
					table += "<td><input   type=\"hidden\" value=\"" + AurlJson[i]
							+ "\"/ id=\"url_" + listIndex + "\">" + AurlJson[i]
							+ "</td>";
					table += "</tr>";
					/*
					 * var tab = document.getElementById("hmhm"); var row =
					 * tab.insertRow(-1); row.id = "row" + i; var cell1 =
					 * row.insertCell(-1); var cell2 = row.insertCell(-1); var
					 * cell3 = row.insertCell(-1); cell1.innerHTML = "<td><input
					 * type=\"checkbox\" value=\"\"/></td>"; cell2.innerHTML = "<td>" +
					 * Arraytitle[i] + "</td>"; cell3.innerHTML = "<td>" +
					 * Aurl[i] + "</td>"; num++;
					 */
					listIndex++;
				}

			}
			table += "</table>";
			var cat_id = MygetItem("set_cat_id");
			var repeat_id = MygetItem("set_repeat_id");
			var partner_id = MygetItem("set_partner_id");
			var album_id = MygetItem("set_album_id");
			var special_id = MygetItem("set_special_id");
			var setDiv = "<div style='display:none;'>";
			setDiv += "<input type=\"text\" id=\"cat_id\" name=\"cat_id\" value=\""
					+ cat_id + "\" />";
			setDiv += "<input type=\"text\" id=\"repeat_id\" name=\"repeat_id\" value=\""
					+ repeat_id + "\" />";
			setDiv += "<input type=\"text\" id=\"partner_id\" name=\"partner_id\" value=\""
					+ partner_id + "\" />";
			setDiv += "<input type=\"text\" id=\"album_id\" name=\"album_id\" value=\""
					+ album_id + "\" />";
			setDiv += "<input type=\"text\" id=\"special_id\" name=\"special_id\" value=\""
					+ special_id + "\" />";
			setDiv += "</div>";
			tab.innerHTML = table + setDiv;
			var hmnum = document.getElementById("hmnum");
			hmnum.innerText = "共" + AurlJson.length + "条信息"; // alert(Aurl.length);
		}else{
			table += "</table>";
			tab.innerHTML = table;
		}
		// 其他浏览器
	} else {
		var table = "<table class=\"tbl lstb\">";
		table += "<tr>";
		table += "<th>选择</th>";
		table += "<th>标题</th>";
		table += "<th>url</th>";
		table += "</tr>";

		/*
		var Arraytitle = JSON.parse(MygetItem("Arraytitle"));
		var Aurl = JSON.parse(MygetItem("Arrayurl"));
		var listIndex = 0;
		if (Aurl != null && Arraytitle != null) {
		*/
		var listIndex = 0;
		var Arraytitle = MygetItem("Arraytitle");
		var Aurl = MygetItem("Arrayurl");
		if (Aurl != null && Arraytitle != null && Aurl !="" && Arraytitle !="" ) {
			var ArraytitleJson = JSON.parse(Arraytitle);
			var AurlJson = JSON.parse(Aurl);
			for ( var i = 0; i < AurlJson.length; ++i) {
				if (AurlJson[i].indexOf(filterKey) >= 0) {
					table += "<tr>";
					table += "<td><input  class=\"checkitem\"  type=\"checkbox\" value=\""
							+ i + "\"/ id=\"id_" + listIndex + "\"></td>";
					table += "<td><input   type=\"hidden\" value=\""
							+ ArraytitleJson[i] + "\"/ id=\"title_" + listIndex + "\">"
							+ ArraytitleJson[i] + "</td>";
					table += "<td><input   type=\"hidden\" value=\"" + AurlJson[i]
							+ "\"/ id=\"url_" + listIndex + "\">" + AurlJson[i] + "</td>";
					table += "</tr>";
					/*
					 * var tab = document.getElementById("hmhm"); var row =
					 * tab.insertRow(-1); row.id = "row" + i; var cell1 =
					 * row.insertCell(-1); var cell2 = row.insertCell(-1); var
					 * cell3 = row.insertCell(-1); cell1.innerHTML = "<td><input
					 * type=\"checkbox\" value=\"\"/></td>"; cell2.innerHTML = "<td>" +
					 * Arraytitle[i] + "</td>"; cell3.innerHTML = "<td>" +
					 * Aurl[i] + "</td>";
					 */
					listIndex++;
				}
			}
			table += "</table>";
			var cat_id = MygetItem("set_cat_id");
			var repeat_id = MygetItem("set_repeat_id");
			var partner_id = MygetItem("set_partner_id");
			var album_id = MygetItem("set_album_id");
			var special_id = MygetItem("set_special_id");
			var setDiv = "<div style='display:none;'>";
			setDiv += "<input type=\"text\" id=\"cat_id\" name=\"cat_id\" value=\""
					+ cat_id + "\" />";
			setDiv += "<input type=\"text\" id=\"repeat_id\" name=\"repeat_id\" value=\""
					+ repeat_id + "\" />";
			setDiv += "<input type=\"text\" id=\"partner_id\" name=\"partner_id\" value=\""
					+ partner_id + "\" />";
			setDiv += "<input type=\"text\" id=\"album_id\" name=\"album_id\" value=\""
					+ album_id + "\" />";
			setDiv += "<input type=\"text\" id=\"special_id\" name=\"special_id\" value=\""
					+ special_id + "\" />";
			setDiv += "</div>";
			tab.innerHTML = table + setDiv;
			var hmnum = document.getElementById("hmnum");
			hmnum.textContent = "共" + AurlJson.length + "条信息";// alert(Aurl.length)
		}else{
			table += "</table>";
			tab.innerHTML = table;
		}
	}
}

/*
 * 取得用户信息
 */
function getuserinfo() {
	var str = "";
	xmlhttp.onreadystatechange = getuserinfoCallback;
	xmlhttp.open("GET", "http://api.cntv.cn/client/getuserinfo", false);
	xmlhttp.setRequestHeader("Content-Type",
			"application/x-www-form-urlencoded");
	xmlhttp.send(str);
}
/*
 * 取得用户信息回调
 */
function getuserinfoCallback() {
	if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
		var username = '';
		var json = JSON.parse(xmlhttp.responseText);
		username = json.username;
		if (typeof (username) == "undefined" || username == "") {
			$("#tabs_div").hide();
			createCode();
			$("#login_div").show();
		} else {
			$("#login_div").hide();
			$("#uname").text(username);
			$("#tabs_div").show();
			// $("#tabs").tabs();
			/*
			 * $('#tabs').bind('tabsselect', function(event, ui) { // ui.tab //
			 * 被选中（点击后）的选项卡元素 // ui.panel // 这个元素包含被选中（点击后）的选项卡的内容 // ui.index //
			 * 返回一个被选中（或点击后）选项卡的索引值（从0开始） if (ui.index == '1') { addTab(); }
			 * else if (ui.index == '2') { batchaddTab(); } else if (ui.index ==
			 * '3') { settingTab(); } else if (ui.index == '4') { videolist(); }
			 * });
			 */
			// tabIndex = MygetItem("tabs");
			// alert(window.location.hash);
			selectTabs(window.location.hash);
			// alert(tabIndex);
			/*
			 * if (tabIndex == '1') { selectTabs("#tabs-1"); } else if (tabIndex ==
			 * '2') { selectTabs("#tabs-2"); } else if (tabIndex == '3') {
			 * selectTabs("#tabs-3"); } else if (tabIndex == '4') {
			 * selectTabs("#tabs-4"); }
			 */
			// change_hash(tabIndex);
		}
	}
}

/*
 * 切换标签 index 选项卡标签需要：1,2...
 */
/*
 * function change_hash(index) { var tabs = $("#tabs").tabs();
 * tabs.tabs('select', index); return false; }
 */

/*
 * 初始化
 */
function initPage() {
	// 判断是否登录
	$("#tabs_div").hide();
	$("#login_div").hide();
	getuserinfo();
}

/*
 * tabs切换
 */
function selectTabs(tabIndex) {
	$("#tabs-1").hide();
	$("#tabs-2").hide();
	$("#tabs-3").hide();
	$("#tabs-4").hide();

	$("#tabsLi-1").removeClass("cur");
	$("#tabsLi-2").removeClass("cur");
	$("#tabsLi-3").removeClass("cur");
	$("#tabsLi-4").removeClass("cur");

	// alert(tabIndex);
	if (tabIndex == '#tabs-1') {
		// alert(tabIndex);
		$("#tabs-1").show();
		$("#tabsLi-1").addClass("cur");
		addTab();
	}
	if (tabIndex == '#tabs-2') {
		// alert(tabIndex);
		$("#tabs-2").show();
		$("#tabsLi-2").addClass("cur");
		batchaddTab();
	}
	if (tabIndex == '#tabs-3') {
		// alert(tabIndex);
		$("#tabs-3").show();
		$("#tabsLi-3").addClass("cur");
		settingTab();
	}
	if (tabIndex == '#tabs-4') {
		// alert(tabIndex);
		$("#tabs-4").show();
		$("#tabsLi-4").addClass("cur");
		var Request = new Object();
		Request = GetRequest();
		page = Request['page'];
		if (!page) {
			page = 1;
		}
		videolist(page);
	}
}
/*
 * 入口程序
 */
$(document).ready(function() {
	initPage();
});

// window.setTimeout(initPage, 500);
